package com.zking.ssm.controller;

import com.zking.ssm.model.HotelSellerEmployee;
import com.zking.ssm.model.HotelsSystem;
import com.zking.ssm.service.IHotelsSystemService;
import com.zking.ssm.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/HotelSystem")
public class HotelSystemController {
    @Autowired
    private IHotelsSystemService hotelsSystemService;

    @RequestMapping("/add")
    public Map<String,Object> add(HotelsSystem hotelsSystem){
        int n = hotelsSystemService.insert(hotelsSystem);
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","增加成功");
        }else{
            map.put("code",-1);
            map.put("message","增加失败");
        }
        return map;
    }

    @RequestMapping("/del")
    public Map<String,Object> del(HotelsSystem hotelsSystem){
        int n = hotelsSystemService.deleteByPrimaryKey(hotelsSystem.getId());
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","删除成功");
        }else{
            map.put("code",-1);
            map.put("message","删除失败");
        }
        return map;
    }

    @RequestMapping("/update")
    public Map<String,Object> update(HotelsSystem hotelsSystem){
        int n = hotelsSystemService.updateByPrimaryKeySelective(hotelsSystem);
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","修改成功");
        }else{
            map.put("code",-1);
            map.put("message","修改失败");
        }
        return map;
    }

    @RequestMapping("/get")
    public Map<String,Object> get(HotelsSystem hotelsSystem){
        HotelsSystem h = hotelsSystemService.selectByPrimaryKey(hotelsSystem.getId());
        Map<String,Object> map = new HashMap<>();
        if(h != null){
            map.put("code",0);
            map.put("message","查询成功");
            map.put("request",h);
        }else{
            map.put("code",-1);
            map.put("message","查询失败");
        }
        return map;
    }

    @RequestMapping("/list")
    public Map<String,Object> list(HotelsSystem hotelsSystem){
        PageBean pageBean = new PageBean();
        List<HotelsSystem> list = hotelsSystemService.selectAll(hotelsSystem, pageBean);
        Map<String,Object> map = new HashMap<>();
        if(list.size() >= 0){
            map.put("code",0);
            map.put("message","查询成功");
            map.put("request",list);
        }else{
            map.put("code",-1);
            map.put("message","查询失败");
        }
        return map;
    }
}
